<?php

/**手机端优惠/资讯/公告综合控制器**/

namespace app\mobile\controller;
use app\common\controller\Base;
use think\Db;
class Show extends Base
{	
	public function _initialize() {
        parent::_initialize();
        $start = array(
	            'user_all'      =>$this->user_all,
	            'app_down' =>$this->app_down,
	            'logo'           =>$this->logo
	    );

        $this->assign($start);
        $this->assign('cur','show');
    }

    /**
     ** 手机端优惠活动列表
    **/
    public function favourable()
    {
    	$youhui_list = Db::name('xt_yhhd_list')->field('id,title,pic,begin_time,end_time')->where('xianshi',1)->order('paixu','DESC')->select();
    	$this->assign('youhui_list',$youhui_list);
        $this->assign('title','优惠活动');
    	return $this->fetch('youhui');
    }

    /**
     ** 手机端优惠活动详情
     **/
    public function youhui_detail()
    {
        $id = input('id') ? input('id') : '';
        if($id) {
            $info = Db::name('xt_yhhd_list')->where(['id'=>$id,'xianshi'=>1])->find();
            $this->assign('info',$info);
            $this->assign('title','优惠活动详情');
            return $this->fetch('youhui_detail');
        }
        $this->redirect('Show/favourable');
    }
    
    /**
     * @Purpose 手机版系统公告
     * @param $page[string 页数]
     * return fetch
     * @Time 2017-11
     */
    public function aboutList()
    {
        $page = input('get.page') ? input('get.page') : 1;
        $page_num = 20;
        //总记录数
        $count = Db::name('xt_gonggao')->where('xianshi',1)->count();
        //总页数
        $total_page = ceil($count / $page_num);
        if($page < 1) $page = 1;
        if($page > $total_page) $page = $total_page;
        //查询带分页的公告信息
        $offset = ($page - 1) * $page_num;
        $about_list = Db::name('xt_gonggao')->where('xianshi',1)->order('paixu','DESC')->limit($offset,$page_num)->select();
        foreach($about_list as &$v) {
            $v['fatime'] = date('Y-m-d H:i:s',$v['fatime']);
        }
        $this->assign('page',$page);
        $this->assign('ns_ls',$about_list);
        $this->assign('title','系统公告');
        return $this->fetch('about_list');
    }


    /**
     * @Purpose 手机版公告详情
     * @param $nid [string 公告id]
     * return fetch
     * @Time 2017-11
     */
    public function aboutDetail()
    {
        $tj = input('tj') ? input('tj') : 1;
        
        $uis = Db::name('xt_gonggao')->where('xianshi',$tj)->select();
        
        $this->assign('uis',$uis);
        if($tj==1){
        	$this->assign('title','系统公告');
        }else{
        	$this->assign('title','平台公告');
        }
        return $this->fetch('about_detail');
    }

}